package com.dongdongshop.data;

import com.dongdongshop.enums.ResultEnum;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = ResultEnum.SUCCESS.getCode();
        result.msg = ResultEnum.SUCCESS.getMessage();
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.code = ResultEnum.SUCCESS.getCode();
        result.msg = ResultEnum.SUCCESS.getMessage();
        result.data = object;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<T>();
        result.code = ResultEnum.FAIL.getCode();
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> error(ResultEnum resultEnum) {
        Result<T> result = new Result<T>();
        result.code = resultEnum.getCode();
        result.msg = resultEnum.getMessage();
        return result;
    }
}
